/*
 * Decompiled with CFR 0.150.
 * 
 * Could not load the following classes:
 *  cn.hutool.core.util.ObjectUtil
 *  com.alibaba.fastjson.JSON
 *  de.felixroske.jfxsupport.FXMLController
 *  javafx.collections.FXCollections
 *  javafx.collections.ObservableList
 *  javafx.event.EventHandler
 *  javafx.fxml.FXML
 *  javafx.fxml.Initializable
 *  javafx.scene.control.Alert
 *  javafx.scene.control.Alert$AlertType
 *  javafx.scene.control.TableColumn
 *  javafx.scene.control.TableView
 *  javafx.scene.control.cell.PropertyValueFactory
 *  javafx.scene.input.KeyCode
 *  javafx.scene.input.KeyEvent
 *  javafx.scene.layout.AnchorPane
 *  javafx.stage.Stage
 *  javafx.util.Callback
 *  org.springframework.beans.factory.annotation.Autowired
 */
package com.gys.controller.clearBox;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.gys.common.business.SalesReceiptsUtil;
import com.gys.common.data.HttpJson;
import com.gys.common.util.SpringUtil;
import com.gys.controller.BaseController;
import com.gys.controller.clearBox.AddClearBoxController;
import com.gys.controller.clearBox.ClearProductQueryController;
import com.gys.controller.dataManger.ControllerManger;
import com.gys.data.clearBox.ClearBoxDetailOutData;
import com.gys.data.clearBox.GetClearQueryProductOutData;
import com.gys.data.salesReceipts.GetPdAndExpOutData;
import com.gys.view.clearBox.ClearPdAndExpView;
import de.felixroske.jfxsupport.FXMLController;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.ResourceBundle;
import java.util.Timer;
import java.util.TimerTask;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Alert;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import javafx.util.Callback;
import org.springframework.beans.factory.annotation.Autowired;

@FXMLController
public class ClearPdAndExpController
extends BaseController
implements Initializable {
    @FXML
    private TableColumn<GetPdAndExpOutData, String> proCode;
    @FXML
    private TableView<GetPdAndExpOutData> tableView;
    @FXML
    private TableColumn<GetPdAndExpOutData, String> proName;
    @FXML
    private TableColumn<GetPdAndExpOutData, String> gssbQty;
    @FXML
    private TableColumn<GetPdAndExpOutData, String> gssbBatchNo;
    @FXML
    private TableColumn<GetPdAndExpOutData, String> gssbVaildDate;
    @FXML
    private AnchorPane pane;
    private Timer timer = new Timer();
    @Autowired
    private AddClearBoxController addClearBoxController;
    @Autowired
    private ClearProductQueryController clearProductQueryController;
    private ObservableList<GetPdAndExpOutData> observableTableList = FXCollections.observableArrayList(new ArrayList());
    private String proCodeParam;
    private GetPdAndExpOutData pdAndExpOutData = null;

    public void initialize(URL location, ResourceBundle resources) {
        ControllerManger.controllerMap.put(this.getClass().getSimpleName(), this);
        this.proCode.setCellValueFactory((Callback)new PropertyValueFactory(this.proCode.getId()));
        this.proName.setCellValueFactory((Callback)new PropertyValueFactory(this.proName.getId()));
        this.gssbQty.setCellValueFactory((Callback)new PropertyValueFactory(this.gssbQty.getId()));
        this.gssbBatchNo.setCellValueFactory((Callback)new PropertyValueFactory(this.gssbBatchNo.getId()));
        this.gssbVaildDate.setCellValueFactory((Callback)new PropertyValueFactory(this.gssbVaildDate.getId()));
        this.init();
    }

    @Override
    public void init() {
        if (ObjectUtil.isEmpty(this.tableView)) {
            return;
        }
        this.pdAndExpOutData = null;
        this.timer.schedule(new TimerTask(){

            @Override
            public void run() {
                ClearPdAndExpView view = SpringUtil.getBean(ClearPdAndExpView.class);
                Stage stage = (Stage)view.getView().getScene().getWindow();
                stage.getScene().setOnKeyReleased((EventHandler)new EventHandler<KeyEvent>(){

                    public void handle(KeyEvent e) {
                        if (e.getCode() == KeyCode.ENTER) {
                            ClearPdAndExpController.this.sureAction();
                        } else if (e.getCode() == KeyCode.UP) {
                            int index;
                            ObservableList outData = ClearPdAndExpController.this.tableView.getSelectionModel().getSelectedItems();
                            if (outData.size() > 1 && (index = ClearPdAndExpController.this.tableView.getSelectionModel().getSelectedIndex()) >= 1) {
                                ClearPdAndExpController.this.tableView.getSelectionModel().select(index - 1);
                            }
                            ClearPdAndExpController.this.tableView.requestFocus();
                        } else if (e.getCode() == KeyCode.DOWN) {
                            int index;
                            ObservableList outData = ClearPdAndExpController.this.tableView.getSelectionModel().getSelectedItems();
                            if (outData.size() > 1 && (index = ClearPdAndExpController.this.tableView.getSelectionModel().getSelectedIndex()) < outData.size() - 1) {
                                ClearPdAndExpController.this.tableView.getSelectionModel().select(index + 1);
                            }
                            ClearPdAndExpController.this.tableView.requestFocus();
                        }
                        e.consume();
                    }
                });
            }
        }, 500L);
        HashMap<String, Object> param = new HashMap<String, Object>();
        param.put("nameOrCode", this.proCodeParam);
        HttpJson httpJson = SalesReceiptsUtil.queryBatchNoAndExp(param);
        List outData = null;
        if (!httpJson.isSuccess()) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", httpJson.getMsg());
            alert.showAndWait();
            return;
        }
        outData = JSON.parseArray((String)httpJson.getMsg(), GetPdAndExpOutData.class);
        this.observableTableList = FXCollections.observableArrayList((Collection)outData);
        this.tableView.setItems(this.observableTableList);
        this.tableView.getSelectionModel().select(0);
        this.tableView.requestFocus();
    }

    @FXML
    private void sureAction() {
        this.pdAndExpOutData = (GetPdAndExpOutData)this.tableView.getSelectionModel().getSelectedItem();
        if (ObjectUtil.isEmpty(this.pdAndExpOutData)) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u672a\u9009\u62e9\u5bf9\u5e94\u8bb0\u5f55\uff0c\u8bf7\u91cd\u65b0\u9009\u62e9\uff01");
            alert.showAndWait();
            return;
        }
        ClearBoxDetailOutData clearBoxDetailOutData = new ClearBoxDetailOutData();
        this.covert(clearBoxDetailOutData, this.clearProductQueryController.getProduct(), this.pdAndExpOutData);
        this.cancelAction();
        this.addClearBoxController.reflsh(clearBoxDetailOutData);
    }

    private void covert(ClearBoxDetailOutData clearBoxDetailOutData, GetClearQueryProductOutData clearQueryProductOutData, GetPdAndExpOutData pdAndExpOutData) {
        clearBoxDetailOutData.setIndexDetail(this.addClearBoxController.getTableView().getItems().size() + 1 + "");
        clearBoxDetailOutData.setGscdProId(clearQueryProductOutData.getProCode());
        clearBoxDetailOutData.setGscdProName(clearQueryProductOutData.getProName());
        clearBoxDetailOutData.setNormalPrice(clearQueryProductOutData.getPrcAmount());
        clearBoxDetailOutData.setGscdBatchNo(pdAndExpOutData.getGssbBatchNo());
        clearBoxDetailOutData.setGscdBatch(pdAndExpOutData.getGssbBatch());
        clearBoxDetailOutData.setGscdValidDate(pdAndExpOutData.getGssbVaildDate());
        clearBoxDetailOutData.setGscdQty(pdAndExpOutData.getGssbQty());
        clearBoxDetailOutData.setQtySour(pdAndExpOutData.getQtySour());
        clearBoxDetailOutData.setProFactoryName(clearQueryProductOutData.getProFactoryName());
        clearBoxDetailOutData.setProPlace(clearQueryProductOutData.getProPlace());
        clearBoxDetailOutData.setProForm(clearQueryProductOutData.getProForm());
        clearBoxDetailOutData.setProUnit(clearQueryProductOutData.getProUnit());
        clearBoxDetailOutData.setProSpecs(clearQueryProductOutData.getProSpecs());
        clearBoxDetailOutData.setProRegisterNo(clearQueryProductOutData.getProRegisterNo());
        clearBoxDetailOutData.setGsadStockStatus("\u6b63\u5e38");
        clearBoxDetailOutData.setGscdSerial(this.tableView.getItems().size() + 1 + "");
    }

    @FXML
    private void cancelAction() {
        this.pane.getScene().getWindow().hide();
    }

    public TableColumn<GetPdAndExpOutData, String> getProCode() {
        return this.proCode;
    }

    public TableView<GetPdAndExpOutData> getTableView() {
        return this.tableView;
    }

    public TableColumn<GetPdAndExpOutData, String> getProName() {
        return this.proName;
    }

    public TableColumn<GetPdAndExpOutData, String> getGssbQty() {
        return this.gssbQty;
    }

    public TableColumn<GetPdAndExpOutData, String> getGssbBatchNo() {
        return this.gssbBatchNo;
    }

    public TableColumn<GetPdAndExpOutData, String> getGssbVaildDate() {
        return this.gssbVaildDate;
    }

    public AnchorPane getPane() {
        return this.pane;
    }

    public Timer getTimer() {
        return this.timer;
    }

    public AddClearBoxController getAddClearBoxController() {
        return this.addClearBoxController;
    }

    public ClearProductQueryController getClearProductQueryController() {
        return this.clearProductQueryController;
    }

    public ObservableList<GetPdAndExpOutData> getObservableTableList() {
        return this.observableTableList;
    }

    public String getProCodeParam() {
        return this.proCodeParam;
    }

    public GetPdAndExpOutData getPdAndExpOutData() {
        return this.pdAndExpOutData;
    }

    public void setProCode(TableColumn<GetPdAndExpOutData, String> proCode) {
        this.proCode = proCode;
    }

    public void setTableView(TableView<GetPdAndExpOutData> tableView) {
        this.tableView = tableView;
    }

    public void setProName(TableColumn<GetPdAndExpOutData, String> proName) {
        this.proName = proName;
    }

    public void setGssbQty(TableColumn<GetPdAndExpOutData, String> gssbQty) {
        this.gssbQty = gssbQty;
    }

    public void setGssbBatchNo(TableColumn<GetPdAndExpOutData, String> gssbBatchNo) {
        this.gssbBatchNo = gssbBatchNo;
    }

    public void setGssbVaildDate(TableColumn<GetPdAndExpOutData, String> gssbVaildDate) {
        this.gssbVaildDate = gssbVaildDate;
    }

    public void setPane(AnchorPane pane) {
        this.pane = pane;
    }

    public void setTimer(Timer timer) {
        this.timer = timer;
    }

    public void setAddClearBoxController(AddClearBoxController addClearBoxController) {
        this.addClearBoxController = addClearBoxController;
    }

    public void setClearProductQueryController(ClearProductQueryController clearProductQueryController) {
        this.clearProductQueryController = clearProductQueryController;
    }

    public void setObservableTableList(ObservableList<GetPdAndExpOutData> observableTableList) {
        this.observableTableList = observableTableList;
    }

    public void setProCodeParam(String proCodeParam) {
        this.proCodeParam = proCodeParam;
    }

    public void setPdAndExpOutData(GetPdAndExpOutData pdAndExpOutData) {
        this.pdAndExpOutData = pdAndExpOutData;
    }

    public boolean equals(Object o) {
        if (o == this) {
            return true;
        }
        if (!(o instanceof ClearPdAndExpController)) {
            return false;
        }
        ClearPdAndExpController other = (ClearPdAndExpController)o;
        if (!other.canEqual(this)) {
            return false;
        }
        TableColumn<GetPdAndExpOutData, String> this$proCode = this.getProCode();
        TableColumn<GetPdAndExpOutData, String> other$proCode = other.getProCode();
        if (this$proCode == null ? other$proCode != null : !this$proCode.equals(other$proCode)) {
            return false;
        }
        TableView<GetPdAndExpOutData> this$tableView = this.getTableView();
        TableView<GetPdAndExpOutData> other$tableView = other.getTableView();
        if (this$tableView == null ? other$tableView != null : !this$tableView.equals(other$tableView)) {
            return false;
        }
        TableColumn<GetPdAndExpOutData, String> this$proName = this.getProName();
        TableColumn<GetPdAndExpOutData, String> other$proName = other.getProName();
        if (this$proName == null ? other$proName != null : !this$proName.equals(other$proName)) {
            return false;
        }
        TableColumn<GetPdAndExpOutData, String> this$gssbQty = this.getGssbQty();
        TableColumn<GetPdAndExpOutData, String> other$gssbQty = other.getGssbQty();
        if (this$gssbQty == null ? other$gssbQty != null : !this$gssbQty.equals(other$gssbQty)) {
            return false;
        }
        TableColumn<GetPdAndExpOutData, String> this$gssbBatchNo = this.getGssbBatchNo();
        TableColumn<GetPdAndExpOutData, String> other$gssbBatchNo = other.getGssbBatchNo();
        if (this$gssbBatchNo == null ? other$gssbBatchNo != null : !this$gssbBatchNo.equals(other$gssbBatchNo)) {
            return false;
        }
        TableColumn<GetPdAndExpOutData, String> this$gssbVaildDate = this.getGssbVaildDate();
        TableColumn<GetPdAndExpOutData, String> other$gssbVaildDate = other.getGssbVaildDate();
        if (this$gssbVaildDate == null ? other$gssbVaildDate != null : !this$gssbVaildDate.equals(other$gssbVaildDate)) {
            return false;
        }
        AnchorPane this$pane = this.getPane();
        AnchorPane other$pane = other.getPane();
        if (this$pane == null ? other$pane != null : !this$pane.equals(other$pane)) {
            return false;
        }
        Timer this$timer = this.getTimer();
        Timer other$timer = other.getTimer();
        if (this$timer == null ? other$timer != null : !this$timer.equals(other$timer)) {
            return false;
        }
        AddClearBoxController this$addClearBoxController = this.getAddClearBoxController();
        AddClearBoxController other$addClearBoxController = other.getAddClearBoxController();
        if (this$addClearBoxController == null ? other$addClearBoxController != null : !(this$addClearBoxController).equals(other$addClearBoxController)) {
            return false;
        }
        ClearProductQueryController this$clearProductQueryController = this.getClearProductQueryController();
        ClearProductQueryController other$clearProductQueryController = other.getClearProductQueryController();
        if (this$clearProductQueryController == null ? other$clearProductQueryController != null : !(this$clearProductQueryController).equals(other$clearProductQueryController)) {
            return false;
        }
        ObservableList<GetPdAndExpOutData> this$observableTableList = this.getObservableTableList();
        ObservableList<GetPdAndExpOutData> other$observableTableList = other.getObservableTableList();
        if (this$observableTableList == null ? other$observableTableList != null : !this$observableTableList.equals(other$observableTableList)) {
            return false;
        }
        String this$proCodeParam = this.getProCodeParam();
        String other$proCodeParam = other.getProCodeParam();
        if (this$proCodeParam == null ? other$proCodeParam != null : !this$proCodeParam.equals(other$proCodeParam)) {
            return false;
        }
        GetPdAndExpOutData this$pdAndExpOutData = this.getPdAndExpOutData();
        GetPdAndExpOutData other$pdAndExpOutData = other.getPdAndExpOutData();
        return !(this$pdAndExpOutData == null ? other$pdAndExpOutData != null : !(this$pdAndExpOutData).equals(other$pdAndExpOutData));
    }

    protected boolean canEqual(Object other) {
        return other instanceof ClearPdAndExpController;
    }

    public int hashCode() {
        int PRIME = 59;
        int result = 1;
        TableColumn<GetPdAndExpOutData, String> $proCode = this.getProCode();
        result = result * 59 + ($proCode == null ? 43 : $proCode.hashCode());
        TableView<GetPdAndExpOutData> $tableView = this.getTableView();
        result = result * 59 + ($tableView == null ? 43 : $tableView.hashCode());
        TableColumn<GetPdAndExpOutData, String> $proName = this.getProName();
        result = result * 59 + ($proName == null ? 43 : $proName.hashCode());
        TableColumn<GetPdAndExpOutData, String> $gssbQty = this.getGssbQty();
        result = result * 59 + ($gssbQty == null ? 43 : $gssbQty.hashCode());
        TableColumn<GetPdAndExpOutData, String> $gssbBatchNo = this.getGssbBatchNo();
        result = result * 59 + ($gssbBatchNo == null ? 43 : $gssbBatchNo.hashCode());
        TableColumn<GetPdAndExpOutData, String> $gssbVaildDate = this.getGssbVaildDate();
        result = result * 59 + ($gssbVaildDate == null ? 43 : $gssbVaildDate.hashCode());
        AnchorPane $pane = this.getPane();
        result = result * 59 + ($pane == null ? 43 : $pane.hashCode());
        Timer $timer = this.getTimer();
        result = result * 59 + ($timer == null ? 43 : $timer.hashCode());
        AddClearBoxController $addClearBoxController = this.getAddClearBoxController();
        result = result * 59 + ($addClearBoxController == null ? 43 : ($addClearBoxController).hashCode());
        ClearProductQueryController $clearProductQueryController = this.getClearProductQueryController();
        result = result * 59 + ($clearProductQueryController == null ? 43 : ($clearProductQueryController).hashCode());
        ObservableList<GetPdAndExpOutData> $observableTableList = this.getObservableTableList();
        result = result * 59 + ($observableTableList == null ? 43 : $observableTableList.hashCode());
        String $proCodeParam = this.getProCodeParam();
        result = result * 59 + ($proCodeParam == null ? 43 : $proCodeParam.hashCode());
        GetPdAndExpOutData $pdAndExpOutData = this.getPdAndExpOutData();
        result = result * 59 + ($pdAndExpOutData == null ? 43 : ($pdAndExpOutData).hashCode());
        return result;
    }

    public String toString() {
        return "ClearPdAndExpController(proCode=" + this.getProCode() + ", tableView=" + this.getTableView() + ", proName=" + this.getProName() + ", gssbQty=" + this.getGssbQty() + ", gssbBatchNo=" + this.getGssbBatchNo() + ", gssbVaildDate=" + this.getGssbVaildDate() + ", pane=" + this.getPane() + ", timer=" + this.getTimer() + ", addClearBoxController=" + this.getAddClearBoxController() + ", clearProductQueryController=" + this.getClearProductQueryController() + ", observableTableList=" + this.getObservableTableList() + ", proCodeParam=" + this.getProCodeParam() + ", pdAndExpOutData=" + this.getPdAndExpOutData() + ")";
    }
}

